package com.zlsy.springbootdemo.classloader;

import lombok.extern.slf4j.Slf4j;
/**
 * @author zhouliang
 * @date 2021/1/9 15:18 jdk的类加载器学习
 */
@Slf4j
public class ClassLoaderStudy {
  public static void main(String[] args) throws ClassNotFoundException {
    String str = "class loader";
    // 输出null：因为这个是虚拟机自身核心的类加载器，不允许外部来改变使用；
    log.info("str（bootstrapClassloader） loader ==>> \n {}", str.getClass().getClassLoader());

    // jdk8输出null jdk9异常输出platformClassloader
    Class<?> driver = Class.forName("java.sql.Driver");
    log.info("driver（platformClassloader） class loader ==>> \n {}", driver.getClassLoader());

    ClassLoaderStudy classLoaderStudy = new ClassLoaderStudy();
    ClassLoader classLoader = classLoaderStudy.getClass().getClassLoader();
    log.info("classLoaderStudy（appClassloader） class loader ==>> \n {}", classLoader);

    log.warn("get classLoaderStudy ClassLoader parent ==>> \n {}", classLoader.getParent());

    MyClassLoader myClassLoader = new MyClassLoader("myClassLoader1");
    Class<?> cls = myClassLoader.loadClass("com.zlsy.springbootdemo.classloader.MyClass");

    log.info("MyClassLoader class loader ==>> \n {}", cls.getClassLoader());
  }
}
